package repositorio;

import java.io.Serializable;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class FabricaBanco implements Serializable{

	private static final long serialVersionUID = -7106337462382517367L;

	@Produces @ApplicationScoped @QualificadorBanco 
	public EntityManagerFactory criarFactory(){		
		
		return Persistence.createEntityManagerFactory("CONEXAO");
		
	}
	
	@Produces @RequestScoped @QualificadorBanco 
	public EntityManager criarEntityManager(@QualificadorBanco EntityManagerFactory factory){
		
		return factory.createEntityManager();
		
	}
		
	@Produces @RequestScoped
	public void finalizaBDA(@QualificadorBanco EntityManager manager) {
		
		manager.close();
		
	}
	
}
